/**
* 左边菜单
*/
<template>
  <el-menu :collapse="collapsed" :default-active="$route.path" active-text-color="#ffd04b" background-color="#334157" class="el-menu-vertical-demo"
           collapse-transition default-active="2" router text-color="#fff"
           unique-opened>
    <div class="logobox">
      <img alt="" class="logoimg" src="../assets/img/logo.png">
    </div>
    <el-submenu v-for="menu in allmenu" :key="menu.id" :index="menu.name">
      <template slot="title">
        <i :class="menu.icon" class="iconfont"></i>
        <span>{{ menu.name }}</span>
      </template>
      <el-menu-item-group>
        <el-menu-item v-for="chmenu in menu.children" :key="chmenu.id" :index="'/'+chmenu.url">
          <i :class="chmenu.icon" class="iconfont"></i>
          <span>{{ chmenu.name }}</span>
        </el-menu-item>
      </el-menu-item-group>
    </el-submenu>
  </el-menu>
</template>
<script>
import {menuTree} from '../api/basisMG';
import $ajax from 'axios';
export default {
  name: 'leftnav',
  data() {
    return {
      collapsed: false,
      allmenu: []
    }
  },
  // 创建完毕状态(里面是操作)
  created() {
    // 获取菜单信息
    menuTree(null)
      .then(res => {
        this.allmenu = res.data;
      })
      .catch(err => {
        this.$message.error(err)
      })

    // 监听
    this.$root.Bus.$on('toggle', value => {
      this.collapsed = !value
    })
  }
}
</script>
<style>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 240px;
  min-height: 400px;
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
  border: none;
  text-align: left;
}

.el-menu-item-group__title {
  padding: 0px;
}

.el-menu-bg {
  background-color: #1f2d3d !important;
}

.el-menu {
  border: none;
}

.logobox {
  height: 40px;
  line-height: 40px;
  color: #9d9d9d;
  font-size: 20px;
  text-align: center;
  padding: 20px 0px;
}

.logoimg {
  height: 40px;
}
</style>
